package com.tanhua.dubbo.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.User;
import com.tanhua.dubbo.UserAPI;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserAPIImpl implements UserAPI {

    //注入Mapper
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile",mobile);

        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public User save(User user) {
        userMapper.insert(user);
        System.out.println("新增user信息："+user);
        return user;
    }

    @Override
    public void update(User newDBUser) {
        userMapper.updateById(newDBUser);
    }

    @Override
    public User findById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public User findByHuanxinId(String huanxinId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hx_user",huanxinId);
        return userMapper.selectOne(queryWrapper);
    }
}
